$(function(){
  var isProcessing = false;
  $('.gallery-nav li a').click(function(){
    $el = $(this);
    var p = $el.parent();
    if(p.hasClass('active') || isProcessing){
      return;
    }
    isProcessing = true;
    var ref = p.data('ref');
    $('.gallery-nav li.active').removeClass("active");
    p.addClass('active');
    var theEl = $('.gallery.active');
    theEl.fadeOut(400,function(){
      theEl.removeClass("active");
      $('#'+ref).fadeIn(400,function(){
        $('#'+ref).addClass('active');
        isProcessing = false;
      });
    });
  });
});